<template>
  <div style="margin-right:50px;">
    <el-form :model="form" status-icon label-width="180px" class="demo-ruleForm" style="margin-top: 50px;" size="mini"
    :rules="rules" ref="form">
      <el-row>
        <el-col :span="8">
          <el-form-item label="债券市场:" prop="market_code">
            <el-select v-model="form.market_code" class="venus-input-middle" filterable clearable placeholder="--请选择--"
               disabled>
              <el-option v-for="(value,key) in dict.markets" :label="value" :value="key" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="债券代码:" prop="bond_code" >
            <el-select v-model="form.bond_code" class="venus-input-middle" filterable clearable placeholder="--请选择--" disabled>
              <el-option v-for="item in dict.bondCode" :label="item.text" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="债券简称:" prop="bond_name" >
            <el-input v-model="form.bond_name" class="venus-input-middle" placeholder="" disabled/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值日期:" prop="tradedate" >
            <el-date-picker v-model="form.tradedate" type="date" value-format="yyyyMMdd" placeholder="选择日期" disabled>
            </el-date-picker>
          </el-form-item>
        </el-col>


        <el-col :span="8">
          <el-form-item label="得尝期(年):" prop="b_anal_matu_cnbd">
            <el-input type='number' v-model="form.b_anal_matu_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>


        <el-col :span="8">
          <el-form-item label="估值全价(元):" prop="b_anal_dirty_cnbd">
            <el-input type='number' v-model="form.b_anal_dirty_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="应计利息(元):" prop="b_anal_accrint_cnbd">
            <el-input type='number' v-model="form.b_anal_accrint_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值净价(元):" prop="b_anal_net_cnbd">
            <el-input type='number' v-model="form.b_anal_net_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值收益率(%):" prop="b_anal_yield_cnbd">
            <el-input type='number' v-model="form.b_anal_yield_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值修正久期:" prop="b_anal_modidura_cnbd">
            <el-input type='number' v-model="form.b_anal_modidura_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值凸性:" prop="b_anal_cnvxty_cnbd">
            <el-input type='number' v-model="form.b_anal_cnvxty_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值基点价值:" prop="b_anal_vobp_cnbd">
            <el-input type='number' v-model="form.b_anal_vobp_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值利差久期:">
            <el-input type='number' v-model="form.b_anal_sprdura_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="估值利差凸性:">
            <el-input type='number' v-model="form.b_anal_sprcnxt_cnbd" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实全价(元):">
            <el-input type='number' v-model="form.b_anal_price" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实净价(元):">
            <el-input type='number' v-model="form.b_anal_netprice" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实收益率(元):">
            <el-input type='number' v-model="form.b_anal_yield" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实修正久期:">
            <el-input type='number' v-model="form.b_anal_modifiedduration" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实凸性:">
            <el-input type='number' v-model="form.b_anal_convexity" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实基点价值:">
            <el-input type='number' v-model="form.b_anal_bpvalue" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实利差久期:">
            <el-input type='number' v-model="form.b_anal_sduration" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="真实利差凸性:">
            <el-input type='number' v-model="form.b_anal_scnvxty" class="venus-input-middle" placeholder="" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="可信度:" prop="b_anal_credibility">
            <el-select v-model="form.b_anal_credibility" class="venus-input-middle" filterable clearable placeholder="--请选择--">
              <el-option v-for="item in dict.credibility" :label="item.value" :value="item.key" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <div class="venus-btn-box" style="text-align: center;">
        <el-button type="success" @click="update('form')">保存</el-button>
        <el-button type="success">取消</el-button>
      </div>
    </el-form>
  </div>

</template>

<script>
  import request from '@/utils/request'
  import * as kk from '@/utils/k-utils'

  export default {
    data() {
      return {
        dict: {
          markets: [],
          bondCode: [],
          credibility: [{
            key: '1',
            value: '推荐'
          }, {
            key: '0',
            value: '不推荐'
          }]
        },
        form: {
          market_code: '',
          bond_code: '',
          bond_name: '',
          tradedate: '',
          b_anal_matu_cnbd: '',
          b_anal_dirty_cnbd: '',
          b_anal_accrint_cnbd: '',
          b_anal_net_cnbd: '',
          b_anal_yield_cnbd: '',
          b_anal_modidura_cnbd: '',
          b_anal_cnvxty_cnbd: '',
          b_anal_vobp_cnbd: '',
          b_anal_sprdura_cnbd: '',
          b_anal_sprcnxt_cnbd: '',
          b_anal_price: '',
          b_anal_netprice: '',
          b_anal_yield: '',
          b_anal_modifiedduration: '',
          b_anal_convexity: '',
          b_anal_bpvalue: '',
          b_anal_sduration: '',
          b_anal_scnvxty: '',
          b_anal_credibility:''
        },
        rules: {
          market_code: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          bond_code: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          bond_name: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          tradedate: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_matu_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_dirty_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_accrint_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_yield_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_net_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_modidura_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_cnvxty_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_vobp_cnbd: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }],
          b_anal_credibility: [{
            required: true,
            message: '该项不允许为空',
            trigger: 'blur'
          }]
        }
      }
    },
    // 生命周期开始
    beforeMount() {

    },
    // 每次打开页面调用，在mounted之后调用
    beforeRouteEnter(to, from, next) {
      // 这里还无法访问到组件实例，this === undefined
      next(vm => {
        // 重置页面数据
        vm.$refs['form'].resetFields()
        //加载市场选项
        kk.k_load_dict(vm, 'markets', 't8_market_code')

        var params = {}
           params.market_code = vm.$route.query.market_code
           params.val = ''
           params.dict = 'bondselect'
           //加载债券代码
        kk.k_load_url('bond', '/getBondInfoSelectList.json', params).then(rep =>{
          vm.dict.bondCode = rep.rows
        })
        vm.form = vm.$route.query
      })
    },
    mounted() {
      this.init()
    },
    // 生命周期结束
    methods: {
      init() {

      },
    update(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
         //修改数据
         kk.k_update_exeid('bond','M8201EUT008', this.form).then(rep => {
           if (rep.success) {
             //关闭当前页面
             kk.k_close_self_page()
           }
         })
        } else {
          console.log('error submit!!');
          return false;
        }
      })

    }
  }

  }
</script>
